package com.gdziarmaga.webshop.web.utils;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SelectorUtils {


    /**
     * Adds a null {@link SelectItem} to selector list.
     * 
     * @param list the list of {@link SelectItem} to add null item
     * @param labelKey the key of label translation property
     * @return the new list of {@link SelectItem}
     */
    public List<SelectItem> addNullSelector(List<SelectItem> list, String labelKey) {
        String label = null;
        if (labelKey != null) {
            label = "null label";
        }
        list.add(0, new SelectItem(null, label));
        return list;
    }

    /**
     * Builds skin selector list.
     * 
     * @return skin selector selector list.
     */
    public List<SelectItem> buildSkinSelector() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem("siiBlueSky"));
        return result;
    }

    /**
     * Builds a list of sex.
     * 
     * @return list of sex
     */
    public List<SelectItem> buildSexSelector() {
        List<SelectItem> result = new ArrayList<SelectItem>();
        result.add(new SelectItem("F", "sex.female"));
        result.add(new SelectItem("M", "sex.male"));
        return result;
    }

    /**
     * Build a number selector list.
     * 
     * @param max the max number
     * @return the number selector list
     */
    public List<SelectItem> buildNumberList(int max) {
        List<SelectItem> result = new ArrayList<SelectItem>();
        for (int i = 1; i < max + 1; i++) {
            result.add(new SelectItem(i));
        }
        return result;
    }
}
